import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/enums/search_type.dart';
import 'package:sainbainu/common/models/request/pager_request.dart';
import 'package:sainbainu/common/models/response/content_response.dart';
import 'package:sainbainu/common/models/response/group_list_response.dart';
import 'package:sainbainu/common/models/response/user_list_response.dart';
import 'package:sainbainu/common/repositories/common_repository.dart';
import 'package:sainbainu/common/repositories/content_repository.dart';
import 'package:sainbainu/common/repositories/group_repository.dart';
import 'package:sainbainu/common/repositories/user_repository.dart';

enum PageType {
  result, // 结果页
  searching, // 搜索面板页
}

class GlobalSearchState {
  // title
  final _title = "".obs;
  set title(value) => _title.value = value;
  get title => _title.value;

  late CommonRepository commonRepository;

  List<String> historyList = [];
  List<String> hotList = [];

  /// 开启历史记录删除
  var enableHistoryDelete = false.obs;

  /// 搜索控制器
  late TextEditingController searchInputController;

  /// 搜索输入框聚焦
  late FocusNode searchFocusNode;

  /// 搜索文本
  var searchText = ''.obs;

  /// 搜索类型
  var pageType = PageType.searching.obs;

  /// 刷新控制器
  late EasyRefreshController refreshController;

  /// tabs 索引
  var tabsIndex = 0.obs;

  /// tabs 索引映射搜索类型
  List<SearchType> tabsIndexToType = [
    SearchType.note,
    SearchType.group,
    SearchType.user,
  ];

  PagerRequest pagerRequest = PagerRequest();

  ContentListResponse noteListResponse = ContentListResponse(
    rows: [],
    total: 0,
  );

  GroupListResponse groupListResponse = GroupListResponse(
    rows: [],
    total: 0,
  );

  UserListResponse userListResponse = UserListResponse(
    rows: [],
    total: 0,
  );

  bool hasMore = false;

  /// 内容仓库
  late ContentRepository contentRepository;
  late GroupRepository groupRepository;
  late UserRepository userRepository;

  var fetchLoading = false.obs;
}
